import { KEYCONST } from "../enums";
export var BSC_ETH_REG = /^0x[a-zA-Z10-9]{40}$/;
export var DID_REG = /^0x[a-zA-Z0-9]{8}$/;
export var CONFLUX_REG = /^(cfx:|cfxtest:)[a-zA-Z0-9]{42}$/;
export default {
    _toFixed: function _toFixed(str1, num) {
        var hanZeo = function hanZeo(z) {
            var zeo = "";
            for(var i = 0; i < z; i++){
                zeo += "0";
            }
            return zeo;
        };
        //小数截取
        var str = String(str1);
        var arr = str.split(".");
        if (arr[1]) {
            if (arr[1].length >= num) {
                return arr[0] + "." + arr[1].slice(0, num);
            } else {
                return arr[0] + "." + arr[1] + hanZeo(num - arr[1].length);
            }
        } else {
            return str + "." + hanZeo(num);
        }
    },
    _formatDatec: function _formatDatec(inputTime) {
        //时间戳格式化
        var date = new Date(parseInt(inputTime * 1000));
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? "0" + m : m;
        var d = date.getDate();
        d = d < 10 ? "0" + d : d;
        var h = date.getHours();
        h = h < 10 ? "0" + h : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? "0" + minute : minute;
        second = second < 10 ? "0" + second : second;
        return h + ":" + minute + " " + m + "/" + d;
    },
    _phoneMethod: function _phoneMethod(cellValue) {
        //电话号码中间用*代替
        if (Number(cellValue) && String(cellValue).length === 11) {
            var mobile = String(cellValue);
            var reg = /^(\d{3})\d{4}(\d{4})$/;
            return mobile.replace(reg, "$1****$2");
        } else {
            return cellValue;
        }
    },
    checkMobile: function checkMobile(sMobile) {
        //判断手机号码的正则表达式
        if (!/^1[3|4|5|6|7|8|9][0-9]\d{8}$/.test(sMobile)) {
            return false;
        } else {
            return true;
        }
    },
    /**
   * 判断邮箱的正则表达式
   * @param {String} 内容
   */ checkEmail: function checkEmail(Email) {
        if (!/^([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\-|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/.test(Email)) {
            return false;
        } else {
            return true;
        }
    },
    _checkPwd: function _checkPwd(pwd) {
        //验证密码，必须8-24字母和数字组成
        // if(!(/^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9]{8,24}$/.test(pwd))) {
        // 	return false;
        // } else {
        // 	return true;
        // }
        if (!/^[a-zA-Z0-9]{8,16}$/.test(pwd)) {
            return false;
        } else {
            return true;
        }
    },
    _checkcode: function _checkcode(code) {
        //验证code，必须6字母和数字组成
        // if(!(/^(?=.*\d)(?=.*[a-zA-Z])[a-zA-Z0-9]{6}$/.test(code))) {
        // 	return false;
        // } else {
        // 	return true;
        // }
        if (!/^(?=.*\d)[0-9]{6}$/.test(code)) {
            return false;
        } else {
            return true;
        }
    },
    _checkpaypwd: function _checkpaypwd(code) {
        //验证密码，必须6位数字组成
        if (!/^(?=.*\d)[0-9]{6}$/.test(code)) {
            return false;
        } else {
            return true;
        }
    },
    /** 检测地址 */ _checkethaddress: function _checkethaddress(code) {
        if (BSC_ETH_REG.test(code) || DID_REG.test(code) || CONFLUX_REG.test(code)) {
            return true;
        }
        return false;
    },
    _formatDate: function _formatDate(inputTime) {
        //时间戳格式化
        var date = new Date(parseInt(inputTime * 1000));
        var y = date.getFullYear();
        var m = date.getMonth() + 1;
        m = m < 10 ? "0" + m : m;
        var d = date.getDate();
        d = d < 10 ? "0" + d : d;
        var h = date.getHours();
        h = h < 10 ? "0" + h : h;
        var minute = date.getMinutes();
        var second = date.getSeconds();
        minute = minute < 10 ? "0" + minute : minute;
        second = second < 10 ? "0" + second : second;
        return y + "-" + m + "-" + d + " " + h + ":" + minute + ":" + second;
    },
    _accMul: function _accMul(arg1, arg2) {
        //乘法
        if (arg1 == 0 || !arg1) {
            return "0";
        }
        if (arg2 == 0 || !arg2) {
            return "0";
        }
        var m = 0, s1 = arg1.toString(), s2 = arg2.toString();
        try {
            m += s1.split(".")[1].length;
        } catch (e) {}
        try {
            m += s2.split(".")[1].length;
        } catch (e) {}
        return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m);
    },
    _accDiv: function _accDiv(arg1, arg2) {
        //除法
        if (arg2 == 0 || !arg2) {
            return "0";
        }
        var t1 = 0, t2 = 0, r1, r2;
        try {
            t1 = arg1.toString().split(".")[1].length;
        } catch (e) {}
        try {
            t2 = arg2.toString().split(".")[1].length;
        } catch (e) {}
        r1 = Number(arg1.toString().replace(".", ""));
        r2 = Number(arg2.toString().replace(".", ""));
        return r1 / r2 * Math.pow(10, t2 - t1);
    },
    toNonExponential: function toNonExponential(num) {
        //处理科学计数的问题
        if (!num) {
            return 0;
        }
        num = parseFloat(num);
        if (isNaN(num)) {
            return 0;
        }
        var m = num.toExponential().match(/\d(?:\.(\d*))?e([+-]\d+)/);
        return num.toFixed(Math.max(0, (m[1] || "").length - m[2]));
    },
    _copy: function _copy(text) {
        //复制文字
        var osName = plus.os.name;
        if (plus.os.name == "Android") {
            var Context = plus.android.importClass("android.content.Context");
            var main = plus.android.runtimeMainActivity();
            var clip = main.getSystemService(Context.CLIPBOARD_SERVICE);
            plus.android.invoke(clip, "setText", text);
        } else if (osName == "iOS") {
            var UIPasteboard = plus.ios.importClass("UIPasteboard");
            var generalPasteboard = UIPasteboard.generalPasteboard();
            // 设置/获取文本内容:
            generalPasteboard.setValueforPasteboardType(text, "public.utf8-plain-text");
        }
    // this._toast("复制成功");
    // this._toast(i18n.t('base.fzcg'));
    },
    _checkCode: function _checkCode(val) {
        var p = /^[1-9]\d{5}(18|19|20)\d{2}((0[1-9])|(1[0-2]))(([0-2][1-9])|10|20|30|31)\d{3}[0-9Xx]$/;
        var factor = [
            7,
            9,
            10,
            5,
            8,
            4,
            2,
            1,
            6,
            3,
            7,
            9,
            10,
            5,
            8,
            4,
            2
        ];
        var parity = [
            1,
            0,
            "X",
            9,
            8,
            7,
            6,
            5,
            4,
            3,
            2
        ];
        var code = val.substring(17);
        if (p.test(val)) {
            var sum = 0;
            for(var i = 0; i < 17; i++){
                sum += val[i] * factor[i];
            }
            if (parity[sum % 11] == code.toUpperCase()) {
                return true;
            }
        }
        return false;
    },
    _levelName: function _levelName(data) {
        switch(data){
            case 0:
                return "levelZero";
            case 1:
                return "levelOne";
            case 2:
                return "levelTwo";
            case 3:
                return "levelThree";
            default:
                return "";
        }
    },
    getwalletid: function getwalletid(e) {
        var _wallet_filter;
        var wallet = JSON.parse(localStorage.getItem(KEYCONST.wallet) || "[]");
        var walletid = (_wallet_filter = wallet.filter) === null || _wallet_filter === void 0 ? void 0 : _wallet_filter.call(wallet, function(res) {
            return e == res.accountCode;
        });
        if ((walletid === null || walletid === void 0 ? void 0 : walletid.length) > 0) {
            var _walletid_;
            return (_walletid_ = walletid[0]) === null || _walletid_ === void 0 ? void 0 : _walletid_.id;
        } else {
            return "";
        }
    }
};

 //# sourceMappingURL=basc.js.map